home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-18 | 2.7 KB | 113 lines | [TEXT/ALFA] |
- // ===========================================================================
- //
- // GSUtilities.c
- //
- // Copyright (C) 1996 Apple Computer, Inc. All rights reserved.
- //
- // ===========================================================================
-
-
- // ===========================================================================
- // Includes
- // ===========================================================================
-
- #include <stdlib.h>
-
- #if (kQAPlatform == kQAMacOS)
- #include <Files.h>
- #include <QuickDraw.h>
- #include <Displays.h>
- #include <Processes.h>
- #endif
-
- #include "GSUtilities.h"
-
-
- #if (kQAPlatform == kQAMacOS)
-
- // ===========================================================================
- // GSFindDeepestMacDisplay
- // ===========================================================================
- // Finds the first screen with the largest greatest depth.
- //
- // RETURNS: handle to the screen device
- //
- GDHandle
- GSFindDeepestMacDisplay(void)
- {
- GDHandle colorGDevice = nil;
- GDHandle deepestGDevice = nil;
- long deviceDepth = 0;
- long maxDepth = 0;
-
- for (colorGDevice = DMGetFirstScreenDevice(dmOnlyActiveDisplays);
- colorGDevice;
- colorGDevice = DMGetNextScreenDevice(colorGDevice, dmOnlyActiveDisplays)) {
- deviceDepth = (**(**colorGDevice).gdPMap).pixelSize;
-
- if (deviceDepth > maxDepth) {
- maxDepth = deviceDepth;
- deepestGDevice = colorGDevice;
- }
- }
-
- return deepestGDevice;
- }
-
- #endif
-
-
- // ===========================================================================
- // GSIsPowerOf2
- // ===========================================================================
- // Determines whether a number is a power of 2.
- //
- // inNumber: the number to check
- // outPower: if not nil, on exit it points to the base-2 log of inNumber
- //
- // RETURNS: true if inNumber is a power of 2, false otherwise
- //
- Boolean
- GSIsPowerOf2(
- unsigned long inNumber,
- unsigned short* outPower)
- {
- unsigned short power = 0;
- Boolean isPowerOf2;
-
- if (inNumber == 0) {
- // zero's not a power of 2 and the loop below won't end if the number
- // is zero, so bail here
- return false;
- }
-
- // loop until we find a 1 in the lowest bit
- while ((inNumber & 1) == 0) {
- inNumber >>= 1;
- power++;
- };
-
- // get rid of the 1 we just found
- inNumber >>= 1;
-
- // if inNumber is a power of 2, it should now be 0. if it has any
- // higher bits set, it won't be 0 and it won't be a power of 2
- isPowerOf2 = (inNumber == 0);
-
- if (isPowerOf2 && (outPower != nil)) {
- *outPower = power;
- }
-
- return isPowerOf2;
- }
-
-
- // ===========================================================================
- // GSRandomFloat
- // ===========================================================================
- float
- GSRandomFloat(void)
- {
- return (rand() / (float) RAND_MAX);
- }
-